package thread;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-03-20
 * Time:23:03
 */
//线程都是并发执行的
public class Demo4 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            while(true){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);//休眠1000ms后此线程状态转为就绪状态
                } catch (InterruptedException e) {//常见的线程受查异常 表示线程异常中止
                    e.printStackTrace();
                }
            }
        });
        t.start();//每隔一秒打印一次
        Thread t2 = new Thread(()->{
            while(true){
                System.out.println("hello thread2");
                try {
                    Thread.sleep(1000);//休眠1000ms后此线程状态转为就绪状态
                } catch (InterruptedException e) {//常见的线程受查异常 表示线程异常中止
                    e.printStackTrace();
                }
            }
        });
        t2.start();
        while(true){
            System.out.println("hello main");//main线程
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


    }
}
